pixelcache: allow widgets to always require cached content
authorChristian Hergert <christian@hergert.me>
Tue, 16 Jun 2015 23:46:24 +0000 (16:46 -0700)
committerChristian Hergert <christian@hergert.me>
Wed, 17 Jun 2015 01:08:22 +0000 (18:08 -0700)
Some widgets have very expensive drawing paths. So caching the content
can be useful even when not scrolling.

This can help speed up widgets that are part of animation sequences and
thereby go through spurious expose events.

https://bugzilla.gnome.org/show_bug.cgi?id=751082

gtk/gtkpixelcache.c
gtk/gtkpixelcacheprivate.h

index 3e883021997308c71b7f2b1024db0d762ccd3f43..a6a85cbb8759483c9af60fc2df5894eb26375024 100644 (file)
@@ -49,6 +49,8 @@ struct _GtkPixelCache {
 
   guint extra_width;
   guint extra_height;
+
+  guint always_cache : 1;
 };
 
 GtkPixelCache *
@@ -224,10 +226,12 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache         *cache,
     }
 
   /* Don't allocate a surface if view >= canvas, as we won't
-     be scrolling then anyway */
+   * be scrolling then anyway, unless the widget requested it.
+   */
   if (cache->surface == NULL &&
-      (view_rect->width < canvas_rect->width ||
-       view_rect->height < canvas_rect->height))
+      (cache->always_cache ||
+       (view_rect->width < canvas_rect->width ||
+        view_rect->height < canvas_rect->height)))
     {
       cache->surface_x = -canvas_rect->x;
       cache->surface_y = -canvas_rect->y;
@@ -483,3 +487,16 @@ _gtk_pixel_cache_unmap (GtkPixelCache *cache)
 {
   gtk_pixel_cache_blow_cache (cache);
 }
+
+gboolean
+_gtk_pixel_cache_get_always_cache (GtkPixelCache *cache)
+{
+  return cache->always_cache;
+}
+
+void
+_gtk_pixel_cache_set_always_cache (GtkPixelCache *cache,
+                                   gboolean       always_cache)
+{
+  cache->always_cache = !!always_cache;
+}
index c31693e140732a1963998977d409bd9bbae512e1..8e1122c36fe98f7bbbcaf19bf9d247afbea3061f 100644 (file)
@@ -30,27 +30,30 @@ typedef struct _GtkPixelCache           GtkPixelCache;
 typedef void (*GtkPixelCacheDrawFunc) (cairo_t *cr,
                                       gpointer user_data);
 
-GtkPixelCache *_gtk_pixel_cache_new            (void);
-void           _gtk_pixel_cache_free           (GtkPixelCache         *cache);
-void           _gtk_pixel_cache_map            (GtkPixelCache         *cache);
-void           _gtk_pixel_cache_unmap          (GtkPixelCache         *cache);
-void           _gtk_pixel_cache_invalidate     (GtkPixelCache         *cache,
-                                                cairo_region_t        *region);
-void           _gtk_pixel_cache_draw           (GtkPixelCache         *cache,
-                                                cairo_t               *cr,
-                                                GdkWindow             *window,
-                                                cairo_rectangle_int_t *view_rect,
-                                                cairo_rectangle_int_t *canvas_rect,
-                                                GtkPixelCacheDrawFunc  draw,
-                                                gpointer               user_data);
-void           _gtk_pixel_cache_get_extra_size (GtkPixelCache         *cache,
-                                                guint                 *extra_width,
-                                                guint                 *extra_height);
-void           _gtk_pixel_cache_set_extra_size (GtkPixelCache         *cache,
-                                                guint                  extra_width,
-                                                guint                  extra_height);
-void           _gtk_pixel_cache_set_content    (GtkPixelCache         *cache,
-                                                cairo_content_t        content);
+GtkPixelCache *_gtk_pixel_cache_new              (void);
+void           _gtk_pixel_cache_free             (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_map              (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_unmap            (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_invalidate       (GtkPixelCache         *cache,
+                                                  cairo_region_t        *region);
+void           _gtk_pixel_cache_draw             (GtkPixelCache         *cache,
+                                                  cairo_t               *cr,
+                                                  GdkWindow             *window,
+                                                  cairo_rectangle_int_t *view_rect,
+                                                  cairo_rectangle_int_t *canvas_rect,
+                                                  GtkPixelCacheDrawFunc  draw,
+                                                  gpointer               user_data);
+void           _gtk_pixel_cache_get_extra_size   (GtkPixelCache         *cache,
+                                                  guint                 *extra_width,
+                                                  guint                 *extra_height);
+void           _gtk_pixel_cache_set_extra_size   (GtkPixelCache         *cache,
+                                                  guint                  extra_width,
+                                                  guint                  extra_height);
+void           _gtk_pixel_cache_set_content      (GtkPixelCache         *cache,
+                                                  cairo_content_t        content);
+gboolean       _gtk_pixel_cache_get_always_cache (GtkPixelCache         *cache);
+void           _gtk_pixel_cache_set_always_cache (GtkPixelCache         *cache,
+                                                  gboolean               always_cache);
 
 
 G_END_DECLS